home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / dflat8.zip / MSGBOX.C < prev    next >
Text File  |  1991-09-30  |  4KB  |  165 lines

  1. /* ------------------ msgbox.c ------------------ */
  2.  
  3. #include "dflat.h"
  4.  
  5. extern DBOX MsgBox;
  6. WINDOW CancelWnd;
  7.  
  8. static int ReturnValue;
  9.  
  10. int MessageBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  11. {
  12.     switch (msg)    {
  13.         case CREATE_WINDOW:
  14.             GetClass(wnd) = MESSAGEBOX;
  15.             ClearAttribute(wnd, CONTROLBOX);
  16.             break;
  17.         case KEYBOARD:
  18.             if (p1 == '\r' || p1 == ESC)
  19.                 ReturnValue = (int)p1;
  20.             break;
  21.         default:
  22.             break;
  23.     }
  24.     return BaseWndProc(MESSAGEBOX, wnd, msg, p1, p2);
  25. }
  26.  
  27. int YesNoBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  28. {
  29.     switch (msg)    {
  30.         case CREATE_WINDOW:
  31.             GetClass(wnd) = MESSAGEBOX;
  32.             ClearAttribute(wnd, CONTROLBOX);
  33.             break;
  34.         case KEYBOARD:    {
  35.             int c = tolower((int)p1);
  36.             if (c == 'y')
  37.                 SendMessage(wnd, COMMAND, ID_OK, 0);
  38.             else if (c == 'n')
  39.                 SendMessage(wnd, COMMAND, ID_CANCEL, 0);
  40.             break;
  41.         }
  42.         default:
  43.             break;
  44.     }
  45.     return BaseWndProc(MESSAGEBOX, wnd, msg, p1, p2);
  46. }
  47.  
  48. int ErrorBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  49. {
  50.     switch (msg)    {
  51.         case CREATE_WINDOW:
  52.             GetClass(wnd) = ERRORBOX;
  53.             break;
  54.         case KEYBOARD:
  55.             if (p1 == '\r' || p1 == ESC)
  56.                 ReturnValue = (int)p1;
  57.             break;
  58.         default:
  59.             break;
  60.     }
  61.     return BaseWndProc(ERRORBOX, wnd, msg, p1, p2);
  62. }
  63.  
  64. int CancelBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  65. {
  66.     switch (msg)    {
  67.         case CREATE_WINDOW:
  68.             CancelWnd = wnd;
  69.             SendMessage(wnd, CAPTURE_MOUSE, 0, 0);
  70.             SendMessage(wnd, CAPTURE_KEYBOARD, 0, 0);
  71.             break;
  72.         case COMMAND:
  73.             if ((int) p1 == ID_CANCEL && (int) p2 == 0)
  74.                 SendMessage(GetParent(wnd), msg, p1, p2);
  75.             return TRUE;
  76.         case CLOSE_WINDOW:
  77.             CancelWnd = NULL;
  78.             SendMessage(wnd, RELEASE_MOUSE, 0, 0);
  79.             SendMessage(wnd, RELEASE_KEYBOARD, 0, 0);
  80.             p1 = TRUE;
  81.             break;
  82.         default:
  83.             break;
  84.     }
  85.     return BaseWndProc(MESSAGEBOX, wnd, msg, p1, p2);
  86. }
  87.  
  88. void CloseCancelBox(void)
  89. {
  90.     if (CancelWnd != NULL)
  91.         SendMessage(CancelWnd, CLOSE_WINDOW, 0, 0);
  92. }
  93.  
  94. int GenericMessage(WINDOW wnd, char *ttl, char *msg, int buttonct,
  95.     int (*wndproc)(struct window *, enum messages, PARAM, PARAM),
  96.     char *b1, char *b2, int c1, int c2, int isModal)
  97. {
  98.     int rtn;
  99.     MsgBox.dwnd.title = ttl;
  100.     MsgBox.ctl[0].dwnd.h = MsgHeight(msg);
  101.     MsgBox.ctl[0].dwnd.w = max(max(MsgWidth(msg),
  102.             buttonct*8 + buttonct + 2), strlen(ttl)+2);
  103.     MsgBox.dwnd.h = MsgBox.ctl[0].dwnd.h+6;
  104.     MsgBox.dwnd.w = MsgBox.ctl[0].dwnd.w+4;
  105.     if (buttonct == 1)
  106.         MsgBox.ctl[1].dwnd.x = (MsgBox.dwnd.w - 10) / 2;
  107.     else    {
  108.         MsgBox.ctl[1].dwnd.x = (MsgBox.dwnd.w - 20) / 2;
  109.         MsgBox.ctl[2].dwnd.x = MsgBox.ctl[1].dwnd.x + 10;
  110.         MsgBox.ctl[2].class = BUTTON;
  111.     }
  112.     MsgBox.ctl[1].dwnd.y = MsgBox.dwnd.h - 4;
  113.     MsgBox.ctl[2].dwnd.y = MsgBox.dwnd.h - 4;
  114.     MsgBox.ctl[0].itext = msg;
  115.     MsgBox.ctl[1].itext = b1;
  116.     MsgBox.ctl[2].itext = b2;
  117.     MsgBox.ctl[1].command = c1;
  118.     MsgBox.ctl[2].command = c2;
  119.     MsgBox.ctl[1].isetting = ON;
  120.     MsgBox.ctl[2].isetting = ON;
  121.     rtn = DialogBox(wnd, &MsgBox, isModal, wndproc);
  122.     MsgBox.ctl[2].class = 0;
  123.     return rtn;
  124. }
  125.  
  126. WINDOW MomentaryMessage(char *msg)
  127. {
  128.     WINDOW wnd = CreateWindow(
  129.                     TEXTBOX,
  130.                     NULL,
  131.                     -1,-1,MsgHeight(msg)+2,MsgWidth(msg)+2,
  132.                     NULL,NULL,NULL,
  133.                     HASBORDER | SHADOW | SAVESELF);
  134.     SendMessage(wnd, SETTEXT, (PARAM) msg, 0);
  135.     if (cfg.mono == 0)    {
  136.         WindowClientColor(wnd, WHITE, GREEN);
  137.         WindowFrameColor(wnd, WHITE, GREEN);
  138.     }
  139.     SendMessage(wnd, SHOW_WINDOW, 0, 0);
  140.     return wnd;
  141. }
  142.  
  143. int MsgHeight(char *msg)
  144. {
  145.     int h = 1;
  146.     while ((msg = strchr(msg, '\n')) != NULL)    {
  147.         h++;
  148.         msg++;
  149.     }
  150.     return min(h, SCREENHEIGHT-10);
  151. }
  152.  
  153. int MsgWidth(char *msg)
  154. {
  155.     int w = 0;
  156.     char *cp = msg;
  157.     while ((cp = strchr(msg, '\n')) != NULL)    {
  158.         w = max(w, (int) (cp-msg));
  159.         msg = cp+1;
  160.     }
  161.     return min(max(strlen(msg),w), SCREENWIDTH-10);
  162. }
  163.  
  164.  
  165.